package com.pengtu.gsj.service.impl.jsbz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.jsbz.RoadMaterialDao;
import com.pengtu.gsj.entity.app.Attachment;
import com.pengtu.gsj.entity.jsbz.RoadMaterial;
import com.pengtu.gsj.service.jsbz.RoadMaterialService;
import com.pengtu.gsj.service.system.SystemManageService;

@Transactional
@Service
public class RoadMaterialServiceImpl implements RoadMaterialService {
	@Autowired
	private RoadMaterialDao roadMateriaDao;
	
	@Autowired
	private SystemManageService systemManageService;
	
	@Override
	public void saveRoadMaterial(RoadMaterial roadMaterial){
		roadMateriaDao.save(roadMaterial);
	}
	
	@Override
	public Page<RoadMaterial> findRoadMaterial(Page<RoadMaterial> page, final QueryFilter queryFilter){
		return roadMateriaDao.findPage(page, queryFilter);
	}
	
	@Override
	public RoadMaterial getRoadMaterialById(String id){
		return roadMateriaDao.get(id);
	}
	
	@Override
	public void  delateRoadMaterial(RoadMaterial roadMaterial){
		if(roadMaterial.getAttachments() != null){
			for(Attachment attachment : roadMaterial.getAttachments()){
				systemManageService.deleteAttachment(attachment);
			}
		}
		roadMateriaDao.delete(roadMaterial);
	}
}
